home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / ActiveX Controlls / NCTAudioEditor2 ActiveX DLL / NCTAudioEditor2.exe / {app} / Samples / TestDelphiAudioEditor2 / Devices.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2003-03-28  |  6.3 KB  |  176 lines

  1. unit Devices;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, ExtCtrls, StdCtrls, NCTAUDIOEDITOR2Lib_TLB, Src, Math, ComCtrls, Adv;
  8.  
  9. type
  10.   TfrmDevices = class(TForm)
  11.     Label1: TLabel;
  12.     Device: TComboBox;
  13.     Panel1: TPanel;
  14.     procedure DeviceClick(Sender: TObject);
  15.     procedure FormShow(Sender: TObject);
  16.   private
  17.     { Private declarations }
  18.     procedure SetSrcOutput;
  19.   public
  20.     { Public declarations }
  21.     Dev: IAudioEditor2Device;
  22.     srcCap: AnsiString;
  23.     flg: Boolean;
  24.     procedure TrackBarChange(Sender: TObject);
  25.     procedure BalanceTrackBarChange(Sender: TObject);
  26.     procedure SrcSelectChange(Sender: TObject);
  27.     procedure AdvClick(Sender: TObject);
  28.   end;
  29.  
  30. var
  31.   frmDevices: TfrmDevices;
  32.  
  33. implementation
  34.  
  35. {$R *.dfm}
  36. //---------------------------------------------------------------------------
  37. procedure TfrmDevices.SetSrcOutput;
  38. var
  39.     CountSrc: Integer;
  40.     i: Integer;
  41.     sf: TsrcFrame;
  42. begin
  43.     CountSrc := Dev.DeviceLines.Count;
  44.     for i := ComponentCount - 1 downto 3 do begin
  45.         sf := TsrcFrame(Components[i]);
  46.         sf.Destroy;
  47.     end;
  48.     Width := Max(255, CountSrc*79+94);
  49.     Left := (Screen.Width - Width) div 2;
  50.     if (CountSrc < 1) then Exit;
  51.     for i:=ComponentCount - 3 to CountSrc do begin                           //Starts a cycle
  52.         sf := TsrcFrame.Create(frmDevices);
  53.         sf.Name := 'sfr'+ IntToStr(i);
  54.         sf.Parent := frmDevices;
  55.         sf.Left := i*79+4;
  56.         sf.Top := 48;
  57.         sf.Width := 81;
  58.         Dev.DeviceLines.Num := i;        //sets input source to the current number
  59.  
  60.         sf.Label1.Caption := Dev.DeviceLines.Name; //Sets srcOutput Caption to the src Input device name
  61.         sf.TrackBar1.Position := 65535 - Dev.DeviceLines.Volume; //sets volume value according to the movement of the slider
  62.         sf.TrackBar1.Tag := i;
  63.         sf.TrackBar1.OnChange := TrackBarChange;
  64.         sf.TrackBar2.Position := Dev.DeviceLines.VolumeBalance; //sets balance value according to the slider position
  65.         sf.TrackBar2.Tag := i;
  66.         sf.TrackBar2.OnChange := BalanceTrackBarChange;
  67.         if (srcCap='Select') then
  68.             sf.CheckBox1.Checked := Dev.DeviceLines.Select
  69.         else
  70.             sf.CheckBox1.Checked :=  Not Dev.DeviceLines.Select;
  71.         sf.CheckBox1.Tag := i;
  72.         sf.CheckBox1.OnClick := SrcSelectChange;
  73.         sf.CheckBox1.Caption := srcCap;
  74.  
  75.         sf.Button1.Tag := i;
  76.         if (Dev.DeviceLines.AdvancedCount >= 0) then sf.Button1.Visible := True //if the current Src has any advanced options then show 'Advanced' button
  77.         else sf.Button1.Visible := False;        //otherwise show no buttons
  78.         sf.Button1.OnClick := AdvClick;
  79.     end;
  80. end;
  81. //---------------------------------------------------------------------------
  82. procedure TfrmDevices.DeviceClick(Sender: TObject);
  83. begin
  84.     Dev.Num := Integer(Device.Items.Objects[Device.ItemIndex]);
  85.     SetSrcOutput();
  86. end;
  87. //---------------------------------------------------------------------------
  88. procedure TfrmDevices.FormShow(Sender: TObject);
  89. var
  90.     kDevInput: Integer;
  91.     i: Integer;
  92. begin
  93.     kDevInput := Dev.Num;        //otherwise kDevOutput equals to the number of output devices on the current machine
  94.     Device.Items.Clear();
  95.     for i:=0 to Dev.Count do begin               //Start cycle which checks if the current device is able to play sound
  96.         Dev.Num := i;             //Sets number of output device to 'i'
  97.         Device.Items.AddObject(Dev.Name, TObject(i));
  98.         if (Dev.DeviceLines.Count < 1) then begin
  99.             if (i = kDevInput) then kDevInput := kDevInput + 1;
  100.         end;
  101.     end;
  102.     if (kDevInput > Dev.Count) then kDevInput := 0; //if the number of the alst of all the audio devices is more than number of devices which are able to playback sound
  103.     Dev.Num := kDevInput;        //the number of device for audio output is set to the last device 'been checked
  104.     Device.ItemIndex  := kDevInput;     //the current device to be shown in the Combo box is set to the last device 'been checked
  105.     SetSrcOutput();
  106. end;
  107. //---------------------------------------------------------------------------
  108. procedure TfrmDevices.TrackBarChange(Sender: TObject);
  109. var
  110.     TrackBar: TTrackBar;
  111.     pos: TPoint;
  112. begin
  113.     TrackBar := TTrackBar(Sender);
  114.     TrackBar.Hint := IntToStr(65535-TrackBar.Position);
  115.     GetCursorPos(pos);
  116.     Application.ActivateHint(pos);
  117.     Dev.DeviceLines.Num := TrackBar.Tag;
  118.     Dev.DeviceLines.Volume := 65535-TrackBar.Position;
  119. end;
  120. //---------------------------------------------------------------------------
  121.  
  122. procedure TfrmDevices.AdvClick(Sender: TObject);
  123. var
  124.     Button: TButton;
  125.     frm: TfrmAdv;
  126. begin
  127.     Button := TButton(Sender);
  128.     Dev.DeviceLines.Num := Button.Tag;
  129.     frm := TfrmAdv.Create(frmDevices);
  130.     frm.m_Rec := True;
  131.     frm.ShowModal();
  132.     frm.Destroy;
  133.  
  134. end;
  135. //---------------------------------------------------------------------------
  136.  
  137. procedure TfrmDevices.BalanceTrackBarChange(Sender: TObject);
  138. var
  139.     TrackBar: TTrackBar;
  140. begin
  141.     TrackBar := TTrackBar(Sender);
  142.     Dev.DeviceLines.Num := TrackBar.Tag;
  143.     Dev.DeviceLines.VolumeBalance := TrackBar.Position;
  144. end;
  145. //---------------------------------------------------------------------------
  146.  
  147. procedure TfrmDevices.SrcSelectChange(Sender: TObject);
  148. var
  149.     CheckBox: TCheckBox;
  150.     sf: TsrcFrame;
  151.     CountSrc: Integer;
  152.     i: Integer;
  153. begin
  154.     if (flg) then Exit;
  155.     flg := True;
  156.     CheckBox := TCheckBox(Sender);
  157.     Dev.DeviceLines.Num := CheckBox.Tag;
  158.     if (srcCap = 'Select') then
  159.         Dev.DeviceLines.Select := CheckBox.Checked
  160.     else
  161.         Dev.DeviceLines.Select := Not CheckBox.Checked;
  162.     CountSrc := Dev.DeviceLines.Count;
  163.     for i:=3 to CountSrc+2 do begin                    //Starts a cycle
  164.         Dev.DeviceLines.Num := i-3;                   //sets input source to the current number
  165.         sf := TsrcFrame(Components[i]);
  166.         if (srcCap = 'Select') then
  167.             sf.CheckBox1.Checked := Dev.DeviceLines.Select
  168.         else
  169.             sf.CheckBox1.Checked := Not Dev.DeviceLines.Select;
  170.     end;
  171.     flg := False;
  172. end;
  173. //---------------------------------------------------------------------------
  174.  
  175. end.
  176.